<template>
  <el-dialog
    :title="!dataForm.id ? '新增' : '修改'"
    :close-on-click-modal="false"
    @close="closeDialog()"
    :visible.sync="visible"
    width="900px">
    <dispense-component  ref="addOrUpdateDispense" @refreshDispenseDataList="refreshDispenseDataList" @disVisible="disVisible"></dispense-component>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()" v-if="canSubmit">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>

  import DispenseComponent from './dispense-component'
  export default {
    data() {
      return {
        visible: false,
        canSubmit: false,
        dataForm: {
          id: '',
        },
        dataRule: {

        }
      }
    },
    components: {
      DispenseComponent
    },
    methods: {
      refreshDispenseDataList (id) {
        this.$emit('refreshDataList')
      },
      disVisible () {
        this.visible = false
      },
      init(id) {
        this.visible = true;
        this.canSubmit = true;
        this.dataForm.id = ''
        this.$nextTick(() => {
          this.$refs.addOrUpdateDispense.init(id)

        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs.addOrUpdateDispense.dataFormSubmit()
      },
      //重置表单
      closeDialog() {
        this.dataForm.id = ''
        this.$refs.addOrUpdateDispense.closeDialog()
        this.$emit('refreshDataList')
      }
    }
  }
</script>

